<?php
function __autoload($class_name) {
    require '../private/'.$class_name.'.php';
}

try{
    $db = new dbaseManager();
    $ptv = new ptvManager();
    $var_account = $_POST['accountdigest'];
	$var_prodid = $_POST['productid'];
	$var_ticket = $_POST['ticket'];

    if($var_account == "" || $var_prodid == ""){
        throw new Exception("incomplete argument list");
    }
    
    if($var_ticket != ""){
        $db->saveTicket($var_account, $var_ticket, $var_prodid);
    }
    
    $ticket = $db->getTicket($var_account, $var_prodid);
    if($ticket == ""){
        // start IAP experience on the connected device
        echo "HAVE2BUY";
    }else{
        // start PTV sequence here
        $ptv->makePTV($ticket, $var_prodid, $db);
    }
    
}catch(Exception $e){
    print "ERROR:  ".$e->getMessage()."</br>".
          "please check <a href=\"http://projects.developer.nokia.com/iap_sample/wiki\">Product Store API</a>";
}

?>
